//package top.lixunda.commerce.common.core.config;
//
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.session.Session;
//import org.springframework.session.web.http.CookieSerializer;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Base64;
//
///**
// * @author lixunda
// * @version time:2020/5/3 2:46
// */
//@Component
//@Slf4j
//@Aspect
//@Configuration
//public class AopSetCookie {
//
//    private SpringSessionCookieSerializer springSessionCookieSerializer
//            = new SpringSessionCookieSerializer();
//
//    /**
//     * 请求的类都是公共方法
//     */
//    @SuppressWarnings("SingleElementAnnotation")
//    @Pointcut("execution(public * org.springframework.session.SessionRepository.createSession(..))")
//    public void pointCut() {
//    }
//
//    @AfterReturning(value = "pointCut()", returning = "object")
//    public void afterReturning(Object object) {
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        if (requestAttributes == null) {
//            log.error("错误！获取ServletRequestAttributes失败，克隆请求header失败，无法进行请求参数转发！请检查RequestInterceptor拦截器是否启动！");
//            return;
//        }
//        HttpServletRequest request = requestAttributes.getRequest();
//        HttpServletResponse response = requestAttributes.getResponse();
//        if (response == null) {
//            log.error("错误！获取HttpServletRequest或HttpServletResponse失败");
//            return;
//        }
//        Session session = (Session) object;
//        this.springSessionCookieSerializer.writeCookieValue(new CookieSerializer.CookieValue(request, response, session.getId()));
//    }
//}
